package com.ymt.bpm.appboot;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

import javax.sql.DataSource;

/**
 * Created by Johnny on 2016/12/25.
 */
public class SqlSessionFactoryConfig {

    @Bean
    public DataSource dataSourceMaster() {
        return DataSourceBuilder.create().build();
    }

    @Autowired
    private DataSource dataSource;


    @Bean
    public SqlSessionFactory sqlSessionFactory() throws Exception {
        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
        bean.setDataSource(dataSource);
        // bean.setConfigLocation(new ClassPathResource("DSMybatisConfig.xml"));
        bean.setMapperLocations(new PathMatchingResourcePatternResolver()
                .getResources("classpath:com/ymt/bpm/dao/*/mysql/*.xml"));
        return bean.getObject();
    }

}
